package com.nd.mobile.study.view;

import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.nd.mobile.study.R;
import com.nd.mobile.study.common.App;
import com.nd.mobile.study.common.BaseActivity;
import com.nd.mobile.study.common.SimpleAsyncTask;
import com.nd.mobile.study.common.constants.BundleConstants;
import com.nd.mobile.study.domain.ClassInfoCatalog;
import com.nd.mobile.study.domain.ClassInfoDetail;

public class ClassInfoDetailActivity extends BaseActivity {

	private TextView			mTVTitle;
	private TextView			mTVDate;
	private TextView			mTVContent;
	private ClassInfoCatalog	mNews;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.news_detail);
	}

	@Override
	protected void initViews() {
		super.initHeader();
		mHeaderTitleTv.setText(R.string.tv_app_myclass_info);
		mHeaderBtnHome.setVisibility(View.VISIBLE);
		mTVTitle = (TextView) findViewById(R.id.news_detail_subtitle);
		mTVDate = (TextView) findViewById(R.id.news_detail_date);
		mTVContent = (TextView) findViewById(R.id.news_detail_content);
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		getIntentData();
		showDetail();
	}

	private void getIntentData() {
		mNews = (ClassInfoCatalog) getIntent().getSerializableExtra(BundleConstants.CLASS_NEWS);
	}

	private void showDetail() {
		mLoading.p();
		new GetDetailTask(this).execute();
	}

	private class GetDetailTask extends SimpleAsyncTask<Void, Void, ClassInfoDetail> {

		public GetDetailTask(Context context) {
			super(context);
		}

		@Override
		protected ClassInfoDetail onLoad(Void... params) throws Exception {
			return mNews.getDetail(App.getInstance().getUser());
		}

		@Override
		protected void onUI(ClassInfoDetail detail) {
			mTVTitle.setText(detail.getTitle());
			mTVDate.setText(detail.getDate());
			mTVContent.setText(Html.fromHtml(detail.getContentNote()));
			mLoading.v();
		}

	}
}
